import 'package:bilibili_flutter/fragment/home_fragment.dart';
import 'package:flutter/material.dart';
import 'package:bilibili_flutter/config/config.dart';
import 'package:bilibili_flutter/view/app_bar_home.dart';

class HomeTabItem {
  const HomeTabItem(String title, IconData icon)
      : assert(title != null, icon != null);
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
    with SingleTickerProviderStateMixin {
  List<Tab> _myTabs = [];

  _HomePageState() {
    getTabList();
  }

  List<Widget> _pageList = [
    HomeFragment(),
    new Container(
      color: Colors.blue,
    ),
    new Container(
      color: Colors.green,
    ),
    new Container(
      color: Colors.grey,
    ),
  ];

  TabController mController;

  List<Tab> getTabList() {
    for (var i = 0; i < TabConfig.HOME_TAB_TITLE.length; i++) {
      _myTabs.add(new Tab(text: TabConfig.HOME_TAB_TITLE[i]));
    }
  }

  @override
  void initState() {
    super.initState();
    mController = TabController(
      length: _myTabs.length,
      vsync: this,
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
            appBar: AppBar(
              elevation: 0.0,
              backgroundColor: Color(ColorS.THEME_COLOR),
              title: HomeAppBarWidget(),
            ),
            body: Column(
              children: <Widget>[
                Container(
                    child: TabBar(
                  isScrollable: true,
                  controller: mController,
                  labelColor: Colors.red,
                  unselectedLabelColor: Color(0xff666666),
                  labelStyle: TextStyle(fontSize: 16.0),
                  tabs: _myTabs,
                )),
                Container(
                  color: Colors.black12,
                  height: 1,
                ),
                Expanded(
                    child: TabBarView(
                  children: _pageList,
                  controller: mController,
                ))
              ],
            )));
  }
}
